<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.fredck.FCKeditor.*,com.gouwudai.gobbs.pojo.TbbsClass"%>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass2.jsp" %>
<%
int classId = ParamUtils.getIntParameter(request, "classId", 0);

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限管理模块 START *********************/
//判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断用户类型 START
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
//判断用户类型 END
if(operatorType<2)
{
	HtmlConst.errors(out,1,"您不是该版的版主，没有当前操作的权限！");
	return;
}
	
userLogin.hasClassPermission(new Integer(classId),4002);//公告管理权限	
/***************** 权限管理模块 END *********************/
String className = currentClass.getClassName();
//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());
%>
<HTML>
<HEAD>
<title>添加公告</title>
<%@ include file="../common/meta.inc" %>
<link href="css/defaultStyle.css" rel="stylesheet" type="text/css">
<script language="javascript" src="${pageContext.request.contextPath}/scripts/common-validator.js"></script>
<script language="javascript" type="text/javascript" src="scripts/showMenu.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
<script language="javascript">
var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);
function doSubmit() {

	form = document.theform;
	
	if(!validateForm(form))
		return;
		
		
    var obj = {};
	obj[Buffalo.BOCLASS] = "com.gouwudai.gobbs.pojo.TbbsAffiche";
	obj.classId=<%=classId%>;
	obj.validDays=parseInt($F('validDays'));
	obj.title=$F('title');
	obj.content=FCKeditorAPI.GetInstance('content').GetXHTML(true);
		
	obj.opUser="<%=LOGIN_ID%>";
	obj.opIp="<%=LOGIN_IP%>";
	obj.createDatetime=new Date();
    buffalo.remoteCall("afficheServiceAjaxService.save",[obj], function(reply) {
        ajaxSubmit(reply.getResult(),"保存成功！","back");
    });
}

function validateForm(form)
{
    if(!sl_check(form.title,"公告主题",50,1)) return false;
    if(!sl_checkIntValue(form.validDays,"有效期",365,0)) return false;
    return sl_confirmUpdate();
}

</script>
</HEAD>
<BODY leftMargin=0 topMargin=0 rightmargin="0" bottommargin="0">
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">
setStatus('<%=SYSTITLE%> - <%=totalClassName.toString() %> - 添加公告');
</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
	<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>&gt;&gt;添加公告
</DIV>
<DIV class="line"></DIV>
<jsp:include flush="true" page="includes/class_manage_menu.jsp?classId=<%=classId %>"></jsp:include>

<table width="99%" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#e6e6e6">
  <tr>
    <td align="center"><strong>添加公告</strong></td>
  </tr>
</table>
<form name="theform" method="post" action="">
						<table width="99%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#e6e6e6">								
							<!-- <tr bgcolor="#f6f6f6">
								<td width="15%" align="right">所属分类/版面:</td>
								<td width="85%">
								<select size="1" name="classId" id="classId" onkeydown="javascript:nextKeyPress(this)">									
									<%//=Arguments.getAllClassOptions(0)%>
								</select>
								</td>
							</tr>	 -->												
							<tr bgcolor="#f6f6f6">
								<td align="right">公告主题:</td>
								<td><input type="text" name="title" id="title" onkeydown="javascript:nextKeyPress(this)" size="20"></td>
							</tr>	
							<tr bgcolor="#f6f6f6">
								<td align="right">有效期:</td>
								<td><input type="text" name="validDays" id="validDays" value="0" onkeydown="javascript:nextKeyPress(this)" size="4" maxlength="4">天<span class="remark">（0为长期有效）</span></td>
							</tr>
							<tr bgcolor="#f6f6f6">
								<td align="right">内容:</td>
								<td>
<%
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "content" ) ;
oFCKeditor.setBasePath( contextPath+"/fckeditor/" ) ;
//oFCKeditor.setValue( "" );
oFCKeditor.setHeight("400");
FCKeditorConfigurations fckConfig = oFCKeditor.getConfig();
fckConfig.put("LinkBrowser","true");//超链浏览
fckConfig.put("ImageBrowser","true");//图片浏览
fckConfig.put("FlashBrowser","true");//FLASH浏览
fckConfig.put("LinkUpload","true");//文件上传
fckConfig.put("ImageUpload","true");//图片上传
fckConfig.put("FlashUpload","true");//FLASH上传
oFCKeditor.setConfig(fckConfig);
out.println( oFCKeditor.create() ) ;
%>	
								</td>
							</tr>																																				
						</table>
						<table border="0" width="100%">
							<tr>
								<td align="right">
								<button class="btn" accessKey=s id="btnSave" name="btnSave" onclick="javascript:doSubmit();">保存(<u>S</u>)</button>
								&nbsp;&nbsp;
								<button class="btn" accessKey=c id="btnCancel" name="btnCancel" onclick="javascript:history.back();">取消(<u>C</u>)</button>
								&nbsp;&nbsp;								
								</td>
							</tr>
						</table>
</form>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>	
</BODY>
</HTML>

